package com.atguigu.date;
import org.junit.Test;

import java.util.Calendar;
import java.util.Date;

public class CalendarTest {
    @Test
    public void test(){
        //1.实例化
        //方式1:去创建其子类(GreorianCalendar)的对象，
        //方式2:使用其静态方法getInstance()
        Calendar instance = Calendar.getInstance();
        System.out.println(instance.getClass());  //也是new的GreorianCalendar的对象
        //2.常用方法
        //get()
        int i = instance.get(Calendar.DAY_OF_MONTH);//获取今天是这个月的第几天
        System.out.println(i);//此时为26
        System.out.println(instance.get(Calendar.DAY_OF_WEEK));//这一周的第几天
        // set()
        instance.set(Calendar.DAY_OF_MONTH,22);
        System.out.println(instance.get(Calendar.DAY_OF_MONTH)); //此时instance本身对象被改了,输出为22
        //add()
        instance.add(Calendar.DAY_OF_MONTH,3);//对instance进行了修改
        System.out.println(instance.get(Calendar.DAY_OF_MONTH));//加了3天，输出为25
        //getTime() 日历类--->Date
        Date date = instance.getTime(); //得到一个date对象
        System.out.println(date);
        //setTime()   Date--->日历类
        Date date2=new Date();
        instance.setTime(date2);
        System.out.println(instance.get(Calendar.DAY_OF_MONTH)); //又变回26号了

    }
}
